<!DOCTYPE html>
<html>
<head>
    <header th:replace="layout/admin/head :: head"></header>
    <!--日期选择器相关-->
    <script type="text/javascript" th:src="@{~/js/bootstrap-datetimepicker.js}"></script>
    <link th:href="@{~/css/bootstrap-datetimepicker.css}" rel="stylesheet"/>
</head>
<body>
<div class="container-fluid">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <div class="row">

                <div class="col-md-2">
                    <button id="doSearch" type="button" class="btn btn-info">查询</button>
                </div>
            </div>
            <br>
            <div class="row">
                <div class="col-md-3">
                    <div class="input-group">
                        <span class="input-group-addon">开始时间：</span>
                        <div id="begin_date" class="input-group date form_datetime" language="zh-CN">
                            <input class="form-control" name="beginDate" size="16" type="text" id="beginDate"/>
                            <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                            <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="input-group">
                        <span class="input-group-addon">结束时间：</span>
                        <div id="end_date" class="input-group date form_datetime">
                            <input class="form-control" name="endDate" size="16" type="text" id="endDate"/>
                            <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                            <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<div class="row">
    <div class="col-md-2">
        <div id="toolbar" class="btn-group">
            <!--            <button id="btn_add" type="button" class="btn btn-default" data-toggle="modal" data-target="#newModal">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                        </button>
                        <button id="btn_edit" type="button" class="btn btn-default">
                            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
                        </button>-->
            <button id="btn_delete" type="button" class="btn btn-default">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
            </button>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <table id="my_table"></table>
    </div>
</div>
</div>

<!--动态查询订单信息的模态窗口-->
<div class="modal fade" id="newModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop='static'>
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true"></span></button>
                <h4 class="modal-title" id="myModalLabel">信息查询</h4>
            </div>
            <div class="modal-body">
                <form id="biz_form">
                                <div class="form-group">
                                    <label for="id">id</label>
                                    <input type="text" class="form-control" id="id" placeholder="id" name="id">
                                </div>
                                <div class="form-group">
                                    <label for="studentNo">编号</label>
                                    <input type="text" class="form-control" id="studentNo" placeholder="编号" name="studentNo">
                                </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    $(function () {
        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();
    });

    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#my_table').bootstrapTable({
                url: '/api/genConfigs',         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortName: 'id',
                sortOrder: "desc",                   //排序方式
                queryParams: oTableInit.queryParams,//传递参数（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: false,                  //是否显示所有的列
                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id",                     //每一行的唯一标识，一般为主键列
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                singleSelect: true,
                // rowStyle: function (row, index) {       //收货信息不匹配的，改变背景色
                //     if (row.isMatch == 0) {
                //         return {classes: 'danger'}
                //     } else if (row.isMatch == 1) {
                //         return {classes: 'success'}
                //     } else {
                //         return {classes: 'info'}
                //     }
                // },
                // classes:'table-striped',
                responseHandler: function (res) {
                    return {
                        "total": res.data.totalElements,
                        "rows": res.data.content
                    }
                },
                columns: [{
                    checkbox: true
                }
                ,{
                    field: 'id',
                    title: 'id'
                }
                ,{
                    field: 'studentNo',
                    title: '编号'
                }
                ,{
                    field: 'studentName',
                    title: '姓名'
                }
                ],
                onExpandRow: function (index, row, $detail) {
                    InitDetail(index, row, $detail);
                }
            });
        }
        //得到查询的参数
        oTableInit.queryParams = function (params) {
            var data = new Object();
            data.size = params.limit;
            data.page = params.offset / params.limit;
            data.sort = params.sort;
            data.order = params.order;
                    if ($('#id').val() != null && $('#id').val() !== "") {
                        data.id = $('#id').val();
                    }
                    if ($('#studentNo').val() != null && $('#studentNo').val() !== "") {
                        data.studentNo = $('#studentNo').val();
                    }
                    if ($('#studentName').val() != null && $('#studentName').val() !== "") {
                        data.studentName = $('#studentName').val();
                    }
            return data;
        };
        return oTableInit;
    };

    $('#doSearch').on('click', function () {
        var opt = {
            silent: true
        };
        $("#my_table").bootstrapTable('refresh', opt);
    })

    var opt = {
        silent: true
    };


    //删除
    $('#btn_delete').on('click', function () {
        //先得选中行
        var row = $("#my_table").bootstrapTable('getSelections');
        if (row != null && row.length > 0) {
            var tokenData = row[0].id;
            $.ajax({
                url: "/api/genConfigs" + "?id=" + tokenData,
                type: "DELETE",
                // data:tokenData,
                // contentType:"application/json",
                success: function (data) {
                    alert("删除成功");
                    $("#my_table").bootstrapTable('refresh', opt);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert("删除失败" + jqXHR.responseJSON.message);
                }
            });
        }
        else {
            alert("请先选择要删除的数据")
        }
    })
    // 关闭模态窗口时进行刷新
    $('#newModal').on('hide.bs.modal', function () {
        $("#my_table").bootstrapTable('refresh', opt);
    })


    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }
</script>


<script type="text/javascript">
    $.fn.datetimepicker.dates['zh-CN'] = {
        days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
        daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
        daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
        months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        today: "今天",
        suffix: [],
        meridiem: ["上午", "下午"]
    };

    $('.form_datetime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        format: 'yyyy-mm-dd hh:ii:ss'
    });

    $(function () {
        //给日期控件赋初始值
        var endDate = new Date();
        var beginDate = endDate.getDate() - 7;
        $("#begin_date").attr("value", beginDate);
        $("#end_date").attr("value", endDate);
    })
</script>

</body>
</html>